package com.liang.controller;


import com.liang.pojo.Armyx;
import com.liang.empty.Result;
import com.liang.security.MySecurity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;;
import java.util.List;
import com.liang.service.ArmyxService;
/**
 *@作者:lsk
 *Controller接口
 *@Date:2023/10/16
*/
@RestController
@RequestMapping("/ArmyxURL")
public class ArmyxController {


	@Autowired
	private ArmyxService armyxservice;






	/**
	根据Army_id查询
	*/
	@MySecurity(methodx = "23")
	@GetMapping("/selectByArmy_id/{army_id}")
	public Result selectByArmy_id(@PathVariable(value = "army_id") Long army_id){
		return Result.buildSuccess(armyxservice.selectByArmy_id(army_id));
	}


	/**
	根据Army_id更新
	*/
//	@PostMapping("/updateByArmy_id")
	public Result updateByArmy_id(@RequestBody Armyx demo){
		return Result.buildSuccess(armyxservice.updateByArmy_id( demo));
	}



	/**
	根据Army_id删除
	*/
	@MySecurity(methodx = "37")
	@GetMapping("/deleteByArmy_id/{army_id}")
	public Result deleteByArmy_id(@PathVariable(value = "army_id") Long army_id){
		return Result.buildSuccess(armyxservice.deleteByArmy_id(army_id));
	}





	/**
	 insert:(插入)
	*/
	@MySecurity(methodx = "27")
	@PostMapping("/insert")
	public Result insert(@RequestBody Armyx demo){
		Result.buildSuccess(armyxservice.insert(demo));
		return Result.buildSuccess(demo);
	}



	/**
	 insertOrUpdate(插入或更新(根据主键或唯一索引更新，主键和唯一索引不会改变))
	*/
	@MySecurity(methodx = "30")
	@PostMapping("/insertOrUpdate")
	public Result insertOrUpdate(@RequestBody Armyx demo){
		return Result.buildSuccess(armyxservice.insertOrUpdate(demo));
	}



	/**
	 insertBath:(批量插入)
	*/
//	@PostMapping("/insertBatch")
	public Result insertBatch(@RequestBody List<Armyx> list){
		return Result.buildSuccess(armyxservice.insertBatch(list));
	}



	/**
	 insertOrUpdateBatch:(批量插入或更新)
	*/
//	@PostMapping("/insertOrUpdateBatch")
	public Result insertOrUpdateBatch(@RequestBody List<Armyx> list){
		return Result.buildSuccess(armyxservice.insertOrUpdateBatch(list));
	}



	/**
	 selectList:(根据参数查询集合)
	*/
	@PostMapping("/selectList")
	public Result selectList(@RequestBody Map<String,Object> param){
		Map map = new HashMap<String,Object>();
		if(param.get("pageNum") != null){
			map.put("total",armyxservice.selectCount(param));
		}
		map.put("data",armyxservice.selectList(param));
		return Result.buildMessage(map,"查询成功",200);
	}



	/**
	 selectCount:(根据集合查询数量)
	*/
//	@PostMapping("/selectCount")
	public Result selectCount(@RequestBody Map<String,Object> param){
		return Result.buildSuccess(armyxservice.selectCount(param));
	}

	/**
	 * 查询军队树结构先查最大的再查子一级
	 */
	@MySecurity(methodx = "23")
	@PostMapping("/selectListAllArmy")
	public Result selectListAllArmy(@RequestBody Map<String,Object> param){
		return Result.buildMessage(armyxservice.selectListAllArmy(param),"查询成功",200);
	}


	/**
	 * 查询军队的职务
	 */
	@PostMapping("/ArmyAndAllDutyxz")
	public Result ArmyAndAllDutyxz(@RequestBody Map<String,Object> param){
		Map map = new HashMap<String,Object>();
		if(param.get("pageNum") != null){
			map.put("total",armyxservice.selectCount(param));
		}
		map.put("data",armyxservice.ArmyAndAllDutyxz(param));
		return Result.buildMessage(map,"查询成功",200);
	}


	/**
	 * 查询军队的职务并且是否职务被担任
	 */
	@PostMapping("/selectArmyDutyUserUser")
	public Result selectArmyDutyUserUser(@RequestBody Map<String,Object> param){
		Map map = new HashMap<String,Object>();
		if(param.get("pageNum") != null){
			map.put("total",armyxservice.selectCount(param));
		}
		map.put("data",armyxservice.selectArmyDutyUserUser(param));
		return Result.buildMessage(map,"查询成功",200);
	}
}